home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
03
/
7
/
DISK0378.ZIP
/
TALLY.DOC
< prev
next >
Wrap
Text File
|
1994-10-26
|
6KB
|
157 lines
TALLY.EXE Page 1
TALLY.EXE is a utility program which counts the number of characters,
words, and lines in an input file. It mirrors the function of WC.EXE
that is included on a number of the larger bulletin boards and also
mirrors the UNIX WC function. I don't know who authored the WC.EXE
program that I have or whether it is the most current release. The
source that I fiddled with came from Kernighan and Ritchie.
WHY ANOTHER VERSION?
1) WC.EXE returns in incorrect character count for text files, as
discussed below under "COMPARISON OF WC.EXE AND TALLY.EXE".
2) WC.EXE was compiled with the C-86 compiler from Computer
Innovations. TALLY.EXE, written with Mark DeSmet's package, seems to
produce a smaller, faster program:
a) WC.EXE, for example, is about 14,000 characters; TALLY
is about 11,000. I don't know how WC was compiled, so I
can't tell why it's smaller, and I'm not claiming any
advantage for DeSmet.
b) Benchmark timing for a large file (43,500 characters) was
54 seconds for WC.EXE and 20 seconds for TALLY, about three
times faster, at least for this application.
TO USE TALLY:
The file you examine should be a text file for results to be
meaningful, but TALLY will still produce a listing for machine code
files without complaint. Invoke the program with the following
command:
TALLY filespec
where filespec is the name of any TEXT(!) file. TALLY will return a
count of:
The number of lines in your input file, including blank
lines. I considered excluding blank lines from the count,
but it seems to me that the number of printer lines would
more often be useful.
The number of words, defined as blank delimited strings.
Something I'm not sure about is special characters that
might be used by text editors and word processors for "soft
returns". I don't think they should appear in an ASCII
file, but I can't be certain. Please let me know if I'm
wrong.
îTALLY.EXE Page 2
The number of text characters in your file, excluding
blanks, carriage returns, linefeeds, tabs, and EOF. (Hex
values 20, 0D, 0A, 09, and 1A, respectively.)
The total number of characters in the file, equal to the
number returned by the DOS DIR command.
COMPARISON OF WC.EXE AND TALLY.EXE:
The first version of TALLY generated some comment on Gene Plantz's
bulletin board that WC and TALLY produced different results. In
checking it out, I fixed two bugs I didn't see during testing (word
and line counts were high by 1) and made some cosmetic changes (see
below). To test the two programs, I built the following file with
EDIX, consisting of 4 lines of "test test test test", resulting in:
test test test test test
test test test test test
test test test test test
test test test test test
Looking at the file with DEBUG or Norton's DISKLOOK, you'll see:
test/test/test/test/test<^
test/test/test/test/test<^
test/test/test/test/test<^
test/test/test/test/test<^
!
Special characters are supplied for illustration only, where:
< represents a carriage return (13 Ascii, 0d Hex),
^ represents a linefeed (10 Ascii, 0a Hex),
! represents an EOF character (26 Ascii, 1a Hex), and
/ represents a blank (32 Ascii, 20 Hex).
The EOF character may or may not be present in your file, depending
on how you create it. If you COPY CON: TEST.TXT, and close it with a
CTRL/Z, it will terminate with Hex 00. This version of TALLY
accounts for both types of text file and will produce the same result
regardless of method.
TALLY.EXE generates this output:
TALLY for test.txt --
-- 5 lines, 20 words, 80 text characters, and 105 total characters.
-- Text excludes blank, return, linefeed, tab, and EOF characters.
-- Line count totals all lines, including blank lines.
îTALLY.EXE Page 3
WC.EXE produces this output for the same file:
Characters = 100, words = 20, lines = 4.
The differences are:
1) WC appears to count spaces as text characters and
excludes either carriage returns or linefeed characters. I
treat all three as "white space" characters in TALLY.
2) Tally supplies a separate grand total of all characters,
agreeing with the DOS directory filesize.
3) If your file exceeds 32,767 characters, WC goes
negative, since it defines its character counter as a
simple integer. Same problem as in Basic. TALLY defines
the counter as an unsigned integer, accurate to 65,536
characters.
4) WC undercounts the number of lines in the file by one.
(So did my first version.) TALLY counts the number of
linefeeds in the file ('\n' characters in "C"). If your
file terminates with a carriage return/linefeed/EOF
combination, it will generate a print line if you TYPE or
print the file, so I count it. If not, I don't.
TALLY is very simple in concept and operation, but it may come in
handy. TALLY.EXE is a public domain utility; you may freely share
it with anyone you choose. I hope you find it helpful.
Comments and suggestions for improvement of the program are welcome.
Thanks to those who commented on the earlier version.
April 15, 1984
Jon Sims
600 C South Blvd.
Evanston, Il 60202 î
April 15, 1984
Jon Sims
600 C South Blvd.
Evanston, Il 60202 î